var prefix = jsctx + "/enterpriseMember";

var subMemberAmountRecord = (function () {
    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
        load();
    };

    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        },10)
    };

    function load() {
        $('#exampleTable')
            .bootstrapTable({
                method: 'get',
                url: prefix + "/listPageSubMemberAmountRecord",
                iconSize: 'outline',
                toolbar: '#exampleToolbar',
                striped: false,
                dataType: "json",
                pagination: true,
                singleSelect: false,
                pageSize: 20,
                pageList: [20],
                pageNumber: 1,
                sidePagination: "server",
                queryParams: function (params) {
                    return {
                        limit: params.limit,
                        offset: (params.offset / params.limit) + 1,
                        memberId: $("#memberId").val().trim(),
                        accountType: $("#accountType").val().trim(),
                        startTime: $("#startTime").val().trim(),
                        recordType: $("#recordType").val().trim(),
                        endTime: $("#endTime").val().trim(),
                        localTradeNo: $("#localTradeNo").val().trim(),
                    };
                },
                columns: [
                    {
                        field: 'number',
                        title: '序号',
                        width: '100', align: 'center',
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },

                    {field: 'nickname', title: '昵称', align: 'center', width: '100'},
                    {field: 'mobile', title: '手机号', align: 'center', width: '100'},
                    {field: 'localTradeNo', title: '本地交易单号', align: 'center', width: '100'},
                    {
                        field: 'accountType',
                        title: '支付的账户类型',
                        width: '100', align: 'center',
                        formatter: function (value, row, index) {
                            if (row.accountType == '0') {
                                return '个人钱包';
                            } else if (row.accountType == '1') {
                                return '企业钱包';
                            } else if (row.accountType == '2') {
                                return '共享钱包';
                            }
                        }
                    },
                    {
                        field: 'recordType', title: '记录类型', width: '100', align: 'left',
                        formatter: function (value, row, index) {
                            if (value == '0') {
                                return '<span >会员在线充值</span>'
                            } else if (value == '1') {
                                return '<span>充电支出</span>'
                            } else if (value == '2') {
                                return '<span>转账收入</span>'
                            } else if (value == '3') {
                                return '<span>企业账号分配</span>'
                            } else if (value == '4') {
                                return '<span>后台订单调整</span>'
                            } else if (value == '5') {
                                return '<span>平台赠送</span>'
                            } else if (value == '6') {
                                return '<span>积分兑换</span>'
                            } else if (value == '7') {
                                return '<span>企业钱包回收</span>'
                            } else if (value == '8') {
                                return '<span>平台钱包充值</span>'
                            } else if (value == '9') {
                                return '<span>分销返利</span>'
                            } else if (value == '10') {
                                return '<span>资源占用费</span>'
                            } else if (value == '11') {
                                return '<span>平台扣费</span>'
                            } else if (value == '12') {
                                return '<span>数据迁移</span>'
                            }else if (value == '13') {
                                return '<span>共享额度变更</span>'
                            }
                        }
                    },
                    {field: 'amount', title: '变更余额', align: 'center', width: '100'},
                    {field: 'result', title: '变更后余额', align: 'center', width: '100'},
                    {field: 'createdTime', title: '变动时间', align: 'center', width: '100'},
                    {field: 'remark', title: '备注', align: 'center', width: '100'},
                ]
            });
    };

    function exportSubMemberAmountRecord() {
        $.fileDownload(prefix + "/exportSubMemberAmountRecord", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                memberId: $("#memberId").val().trim(),
                accountType: $("#accountType").val().trim(),
                startTime: $("#startTime").val().trim(),
                recordType: $("#recordType").val().trim(),
                endTime: $("#endTime").val().trim(),
                localTradeNo: $("#localTradeNo").val().trim(),
                count: $("#count").val().trim() == '' ? 0 : $("#count").val().trim(),
                offset: $('.active .page-link').text(),
                limit: $(".page-size").text()
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }


    return {
        init: init,
        reLoad: reLoad,
        exportSubMemberAmountRecord:exportSubMemberAmountRecord
    };
})();
